package com.xdb.sqlparser.ast.statement;

import java.util.ArrayList;
import java.util.List;

import com.xdb.sqlparser.ast.SQLExpr;
import com.xdb.sqlparser.ast.AbstractSQLObjectImpl;
import com.xdb.sqlparser.visitor.SQLAstVisitor;
/**
 * SQL查询子句中的Group By子句
 * 
 * @author woate
 *
 */
public class SQLSelectGroupByClause extends AbstractSQLObjectImpl {
	/**
	 * Group By 子句之后的标识符
	 */
	private final List<SQLExpr> items = new ArrayList<SQLExpr>();
	/**
	 * having 子句对象
	 */
	private SQLExpr having;

	public SQLSelectGroupByClause() {

	}

	protected void accept0(SQLAstVisitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.items);
			acceptChild(visitor, this.having);
		}

		visitor.endVisit(this);
	}

	public SQLExpr getHaving() {
		return this.having;
	}

	public void setHaving(SQLExpr having) {
		this.having = having;
	}

	public List<SQLExpr> getItems() {
		return this.items;
	}
	/**
	 * 将Group By 之后的标识加入当前对象
	 * 
	 * @param sqlExpr
	 */
	public void addItem(SQLExpr sqlExpr) {
		if (sqlExpr != null) {
			sqlExpr.setParent(this);
			this.items.add(sqlExpr);
		}
	}
}
